package com.ruoyi.business.component.mqconsumer.repaymentconsumers;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.bizsys.domain.RepaymentOrder;
import com.ruoyi.bizsys.mapper.RepaymentOrderMapper;
import com.ruoyi.bizsys.utils.BizConstants;
import com.ruoyi.business.service.IBRepaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 溢缴款冲账MQ
 * @author wqg
 * @description
 * @date 2022/5/21
 */
@Slf4j
@Service(BizConstants.ROCKMQ_REPAYMENT_TYPE_OVERFLOW_MQSERVICE)
public class OverflowRepaymentConsumer implements IRepaymentMqService{

    @Autowired
    IBRepaymentService ibRepaymentService;
    @Autowired
    RepaymentOrderMapper repaymentOrderMapper;
    /**
     * @param msgObj
     */
    @Override
    public void handle(JSONObject msgObj) {
        log.info("溢缴款冲账MQ：data:{}", msgObj.toString());
        RepaymentOrder repaymentOrder = msgObj.getObject("repaymentOrder",RepaymentOrder.class);
        long creditAccountId = msgObj.getLong("creditAccountId");
        repaymentOrder = repaymentOrderMapper.getDetail(repaymentOrder.getRepaymentNo());
        if(null!=repaymentOrder && repaymentOrder.getRepayStatus()==BizConstants.REPAYMENT_ORDER_STATUS_SUCCESS){
            log.info("repaymentOrder.getRepayStatus():"+repaymentOrder.getRepayStatus());
            return;
        }
        ibRepaymentService.overflowRepaymentMq(repaymentOrder,creditAccountId);
        log.info("溢缴款冲账MQ-Repayment-end：data:{}",msgObj);

    }
}
